﻿using System;

class BitAtPositionIs1
{
    static void Main()
    {
        //Exercise 10.
        //Write a boolean expression that returns if the bit at position p (counting from 0) in a given integer 
        //number v has value of 1. Example: v=5; p=1 -> false.

        Console.Write("Enter an integer: ");
        int v = int.Parse(Console.ReadLine());
        Console.Write("Enter the position: ");
        int p = int.Parse(Console.ReadLine());        
        Console.WriteLine(Convert.ToString(v, 2).PadLeft(32, '0')); //I use this to check whether the code works properly.
        int mask = 1 << p;
        int result = v & mask;
        int finalresult = result >> p;
        //Console.WriteLine(finalresult);   //I use this to check whether the code works properly.
        bool check = (finalresult == 1);
        Console.WriteLine(check);
        Console.WriteLine("Whether the bit at position {0} in number {1} has value of 1? - {2}", p, v, check);
    }
}

